package com.office.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.office.common.Response;
import com.office.mapper.OfficeDataMapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/officeData")
public class OfficeDataController {

    @Resource
    private OfficeDataMapper officeDataMapper;

    @DeleteMapping("/{id}")
    public Response<?> delete(@PathVariable Integer id) {
        try {
            officeDataMapper.deleteById(id);
            return Response.success();
        } catch (Exception e) {
            e.printStackTrace();
            return Response.error("-1", "删除异常");
        }
    }

    @PostMapping("/deleteBatch")
    public Response<?> deleteBatch(@RequestBody List<Integer> ids) {
        try {
            officeDataMapper.deleteBatchIds(ids);
            return Response.success();
        } catch (Exception e) {
            e.printStackTrace();
            return Response.error("-1", "批量删除异常");
        }
    }

    @GetMapping("/findPage")
    public Response<?> findPage(@RequestParam(defaultValue = "1") Integer pageNum,
                                @RequestParam(defaultValue = "10") Integer pageSize) {
        return Response.success(officeDataMapper.selectPage(new Page<>(pageNum, pageSize), null));
    }

}


